package com.sanpu.kxe.business.repay.adapter;

import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.repay.bean.QueryPlanOutput;

import java.util.ArrayList;

/**
 * 查询计划adpter
 * Created by Administrator on 2018/5/16.
 */

public class QueryPlanAdapter extends BaseQuickAdapter<QueryPlanOutput, BaseViewHolder> {

    public QueryPlanAdapter() {
        super(R.layout.item_query_plan, new ArrayList<QueryPlanOutput>());
    }

    @Override
    protected void convert(BaseViewHolder helper, QueryPlanOutput item) {
        if (item != null) {
            helper.setText(R.id.tradeTimeTv, "计划时间：" + item.getTradeTime())
                    .setText(R.id.actualPaymentCountTv, "已还款笔数：" + item.getActualPaymentCount())
                    .setText(R.id.expectedTradeAmountTv, "计划消费金额：" + item.getExpectedTradeAmount() + "元")
                    .setText(R.id.expectedPaymentAmountTv, "计划还款金额：" + item.getExpectedPaymentAmount() + "元")
                    .setText(R.id.actualTradeAmountTv, "实际消费金额：" + item.getActualTradeAmount() + "元")
                    .setText(R.id.actualPaymentAmountTv, "实际还款金额：" + item.getActualPaymentAmount() + "元")
                    .addOnClickListener(R.id.takeDetailsRtv)
                    .setGone(R.id.failCauseTv, !TextUtils.isEmpty(item.getFailCause()))
                    .setText(R.id.failCauseTv, "失败原因：" + item.getFailCause());

            TextView planStatusTv = helper.getView(R.id.planStatusTv);
            ImageView planStatusIv = helper.getView(R.id.planStatusIv);
            setViewByPlanStatus(planStatusTv, planStatusIv, item.getPlanStatus());
        }
    }

    /**
     * 根据计划状态显示view
     */
    private void setViewByPlanStatus(TextView planStatusTv, ImageView planStatusIv, String planStatus) {
        switch (planStatus) {
            case "INIT":
                planStatusTv.setText("初始化");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_fd8f1a));
                planStatusIv.setImageResource(R.drawable.img_plan_proces);
                break;
            case "WATING":
                planStatusTv.setText("待执行");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_fd8f1a));
                planStatusIv.setImageResource(R.drawable.img_plan_proces);
                break;
            case "PROCESING":
                planStatusTv.setText("执行中");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_fd8f1a));
                planStatusIv.setImageResource(R.drawable.img_plan_proces);
                break;
            case "CANCEL":
                planStatusTv.setText("已取消");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_ff3f40));
                planStatusIv.setImageResource(R.drawable.img_plan_fail);
                break;
            case "SUCCESS":
                planStatusTv.setText("执行成功");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_4361ff));
                planStatusIv.setImageResource(R.drawable.img_plan_success);
                break;
            case "FAIL":
                planStatusTv.setText("执行失败");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_ff3f40));
                planStatusIv.setImageResource(R.drawable.img_plan_fail);
                break;
            case "COMPENSATING":
                planStatusTv.setText("补偿中");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_fd8f1a));
                planStatusIv.setImageResource(R.drawable.img_plan_proces);
                break;
            case "COMPENSATE_SUCCESS":
                planStatusTv.setText("补偿成功");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_4361ff));
                planStatusIv.setImageResource(R.drawable.img_plan_success);
                break;
            case "COMPENSATE_FAIL":
                planStatusTv.setText("补偿失败");
                planStatusTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_ff3f40));
                planStatusIv.setImageResource(R.drawable.img_plan_fail);
                break;
        }
    }
}
